﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataHelper;
using Utils;
namespace DAL
{
  public  class TrainDao
    {

   
      #region 培训
        public bool Insert(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().InsertTable(tableName, sdList);
        }


        public bool Update(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().UpdateTable(tableName, sdList);
        }

      public bool DeleteOneInfo(string trainID)
      {
          return SQLHelper.ExecuteSqlWithTransaction("Delete from Admin_Train Where TrainID=" + trainID);
      }
      //获取一条记录
      public DataTable GetOneInfo(string trainID)
      {
          return SQLHelper.ExecuteSqlGetDrToDt("Select * from Admin_Train Where TrainID=" + trainID);
      }
      //SQL
      public string GetSQL(string serWord, string deptName, string bTime, string eTime)
      {
          StringBuilder strSQL = new StringBuilder("Select * From Admin_Train Where 1=1 ");
          if (!string.IsNullOrWhiteSpace(serWord))
              strSQL.Append(" And (EmpCode='" + serWord + "' Or EmpName Like '%" + serWord + "%')");
          if (!string.IsNullOrWhiteSpace(deptName) && deptName != "请选择部门")
              strSQL.Append(" And DeptName ='" + deptName + "'");
          if (RegexRule.IsDate(bTime))
              strSQL.Append(" And TrainTime>='" + bTime + "'");
          if (RegexRule.IsDate(eTime))
              strSQL.Append(" And TrainTime<='" + eTime + "'");
          return strSQL.ToString();
      }
      //列表
      public DataTable GetLists(string serWord, string deptName, string bTime, string eTime)
      {
          DataTable dt = SQLHelper.ExecuteSqlGetDrToDt(GetSQL(serWord, deptName, bTime, eTime));
          //if (dataSet.Tables[0].Rows.Count <= 0)
          //{
          //    for (int i = 0; i < 5; i++)
          //    {
          //        DataRow dr = dataSet.Tables[0].NewRow();
          //        dataSet.Tables[0].Rows.Add(dr);
          //    }
          //}
          return dt;
      }
      #endregion
    }
}
